import cv2 as cv
import numpy as np

def Harris_detect(img):
    gray_img = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
    gray_img = np.float32(gray_img)
    #对图像执行harris
    Harris_detector = cv.cornerHarris(gray_img, 2, 3, 0.04)
    #腐蚀harris结果
    dst = cv.dilate(Harris_detector, None)
    # 设置阈值
    thres = 0.1*dst.max()
    img[dst > thres] = [255,0,0]
    cv.imshow('show', img)


#均值模糊
def  blur(img): #去燥  基于卷积
    dst = cv.blur(img , (5 ,5))  #卷积核大小（1*3）
    cv.namedWindow("blur", cv.WINDOW_AUTOSIZE)
    cv.imshow("blur", dst)

def mean(img):  #去椒盐噪声  基于卷积
    dst = cv.medianBlur(img , 5)
    cv.namedWindow("mean", cv.WINDOW_AUTOSIZE)
    cv.imshow("mean", dst)

def own_blur( img ):  #自定义模糊
    kernel = np.ones([5,5],np.float32)/25  #均值模糊，除以5*5防止溢出
    kernel1 = np.array([[0,-1,0],[-1,5,-1],[0,-1,0]], np.float32) #锐化算子
    dst = cv.filter2D( img , -1 , kernel1)
    cv.namedWindow("own_blur", cv.WINDOW_AUTOSIZE)
    cv.imshow("own_blur", dst)


if __name__ == '__main__':
    img = cv.imread("F:\\ml\\moban\\wowtest02.jpg")    
    blur(img)
    mean(img)
    own_blur(img)
    #Harris_detect(src)
        
    cv.waitKey(0)
    cv.destroyAllWindows()





